package com.lm.csv.example;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

import java.io.FileWriter;
import java.io.IOException;

public class CsvWriterExample {
    public static void main(String[] args) throws IOException {
        // 创建 CSV 文件
        try (FileWriter writer = new FileWriter("e:\\csv\\output.csv");
             CSVPrinter printer = new CSVPrinter(writer, CSVFormat.DEFAULT
                     .withHeader("ID", "Name", "Age", "Email"))) {

            printer.printRecord("1", "Alice", "25", "alice@example.com");
            printer.printRecord("2", "Bob", "30", "bob@example.com");
            printer.printRecord("3", "Charlie", "35", "charlie@example.com");
        }
    }
}
